using System;
using EventBehaviorTree;

namespace BuffSystem
{
    [Serializable]
    public class TriggerEvent : CarrierComponent, ICondition
    {
        private TriggerType _triggerType;
        private bool _condition;
        public TriggerEvent(string occupantKey, TriggerType triggerType) : base(occupantKey)
        {
            _triggerType = triggerType;
            _occupantType = OccupantType.TriggerEvent;
            _condition = false;
        }
        public TriggerEvent(string occupantKey, string triggerType) : base(occupantKey)
        {
            _triggerType = (TriggerType)Enum.Parse(typeof(TriggerType), triggerType);
            _occupantType = OccupantType.TriggerEvent;
            _condition = false;
        }
        public override void RegisterPrepare(Buff buff, BuffManager owner, BuffManager target)
        {
            base.RegisterPrepare(buff, owner, target);
            _target.RegisterTrigger(_occupantKey.ToString(), _triggerType, delegate { _condition = true; });
        }
        public override void Unregister() { _target.UnregisterTrigger(_occupantKey.ToString(), _triggerType); }
        public bool Condition() { return _condition; }
        public void ResetCondition() { _condition = false; }
    }
}
